package cn.itsource.pethome.org.mapper;

import cn.hutool.core.collection.CollectionUtil;
import cn.itsource.pethome.base.superr.MyBaseMapper;
import cn.itsource.pethome.org.domain.Employee;

import java.util.List;

public interface EmployeeMapper extends MyBaseMapper<Employee> {

    default Class<Employee> getTClass(){
       return Employee.class;
    };

    /**
     * 通过邮箱查询该用户
     * @param email
     * @return
     */
    default Employee findByEmail(String email){
        //就是你对这个员工对象,哪个字段有值,他就会帮助你拼接成and条件,去查询
        Employee employee = new Employee();
        employee.setEmail(email);
        List<Employee> select = this.select(employee);
        if (CollectionUtil.isEmpty(select)){
            return null;
        }else {
            return select.get(0);
        }
    };

    default Employee findByUsername(String username){
        Employee employee = new Employee();
        employee.setUsername(username);
        List<Employee> select = this.select(employee);
        if (CollectionUtil.isEmpty(select)){
            return null;
        }else {
            return select.get(0);
        }
    };

    /**
     * mapper高级查询
     * @param query
     * @return
     */
//    default List<Department> findPage(BaseQuery query){
//        //1.创建一个 example
//        Example example = new Example(Department.class);
//        //2.获取条件
//        Example.Criteria criteria = example.createCriteria();
//        //StrUtil.isBlank 除了判断是否为null 还判断当前的数据类型 以及是否为""
//        if (StrUtil.isBlank(query.getKeyword())){
//            return this.selectAll();
//            //3条件查询
//        }else {
//            criteria.andLike("name","%"+query.getKeyword()+"%");
//            return this.selectByExample(example);
//        }
//
//
//
//    }

}
